#ifndef IDLE_EVENT_H

#define IDLE_EVENT_H

#include "raw_type.h"
#include "raw_internal_type.h"
#include "raw_list.h"
#include "raw_stm.h"

typedef struct IDLE_QUEUE_MSG {

	RAW_U16 sig;
	void *para;
	
} IDLE_QUEUE_MSG;


typedef struct ACTIVE_EVENT_STRUCT {

	STM_STRUCT super;                
	
	RAW_TICK_TYPE tick_ctr;
	
	LIST   idle_tick_list;
		
	RAW_U8 head;

	RAW_U8 prio;
	
	RAW_U8 tail;
	
	RAW_U8 nUsed;
	
	RAW_U8 priority_bit_x;
	RAW_U8 priority_bit_y;

	RAW_U8 priority_x;
	RAW_U8 priority_y;

} ACTIVE_EVENT_STRUCT;


typedef struct ACTIVE_EVENT_STRUCT_CB {
    ACTIVE_EVENT_STRUCT *act;        
    IDLE_QUEUE_MSG    *queue;          
    RAW_U8 end;                 
	
} ACTIVE_EVENT_STRUCT_CB;


#define  ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#define  RAW_IDLE_LOWEST_PRIO 63u
#define  RAW_IDLE_RDY_TBL_SIZE ((RAW_IDLE_LOWEST_PRIO) / 8u + 1u)

#define SEND_TO_FRONT     0x1
#define SEND_TO_END       0x2

void    event_init(void);
RAW_U16 event_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para, RAW_U8 opt_send_method);
RAW_U16 event_end_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para);
RAW_U16 event_front_post(ACTIVE_EVENT_STRUCT *me, RAW_U16 sig, void *para);
void    event_tick_isr(void);
RAW_U16 event_tick_arm(ACTIVE_EVENT_STRUCT *me, RAW_TICK_TYPE ticks);
RAW_U16 event_tick_disarm(ACTIVE_EVENT_STRUCT *me);
void    event_sche(void); 
void    event_user(void);

#endif

